<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.css">
<title>Home</title>
</head>
<body>
</body>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
<script type="text/javascript">
	/* var BicycleShop = function(name){
		this.name = name;
		this.method=function(){
			return this.name;
		}
	};
	
	BicycleShop.prototype={
			constructor:BicycleShop,
			
			sellBicycle:function(model){
				var bicycle = this.createBicycle(model);
				
				return bicycle;
			},
			createBicycle:function(model){
				throw new Error("父类是抽象类不能直接调用，需要子类重写该方法");
			}
	}
	
	function extend(sub,sup){
		//Sub表示子类，Sup表示超类
        // 首先定义一个空函数
        var F = function(){};
        // 设置空函数的原型为超类的原型
        F.prototype = sup.prototype;
     	// 实例化空函数，并把超类原型引用传递给子类
        sub.prototype = new F();
     	// 重置子类原型的构造器为子类自身
        sub.prototype.constructor = sub;
     	
     	// 重置子类原型的构造器为子类自身
        sub.sup = sup.prototype;
        if(sup.prototype.constructor === Object.prototype.constructor) {
            // 检测超类原型的构造器是否为原型自身
            sup.prototype.constructor = sup;
        }
	}
	
	var BicycleChild = function(name){
        this.name = name;
		// 继承构造函数父类中的属性和方法
        BicycleShop.call(this,name);
    };
    
    // 子类继承父类原型方法
    extend(BicycleChild,BicycleShop);
	// BicycleChild 子类重写父类的方法
	BicycleChild.prototype.createBicycle = function(){
	    var A = function(){
	        console.log("执行A业务操作");    
	    };
	    var B = function(){
	        console.log("执行B业务操作");
	    };
	    return {
	        A: A,
	        B: B
	    }
	}
	var childClass = new BicycleChild("龙恩");
	debugger;
	childClass.__proto__
	console.log(childClass); */
	
	// 单体模式
	var Singleton = function(name){
	    this.name = name;
	    this.instance = null;
	};
	Singleton.prototype.getName = function(){
	    return this.name;
	}
	// 获取实例对象
	function getInstance(name) {
	    if(!this.instance) {
	        this.instance = new Singleton(name);
	    }
	    return this.instance;
	}
	// 测试单体模式的实例
	var a = getInstance("aa");
	var b = getInstance("bb");
	console.log(a === b);
</script>
</html>